const path = require("path");
const { override, addWebpackAlias } = require("customize-cra");
module.exports = (config, env) => {
  const aliacFunc = addWebpackAlias({ "@": path.resolve(__dirname, "src") });
  //   const entryFunc = config => {
  //	 const fs = require("fs");
  //     let starterFolderName;
  //     const srcDirPath = path.resolve(__dirname, "src");
  //     const moduleFolderPaths = fs
  //       .readdirSync(srcDirPath)
  //       .sort((p, n) => p.localeCompare(n))
  //       .map(folderName => path.resolve(srcDirPath, folderName))
  //       .filter(folderPath => fs.existsSync(folderPath))
  //       .forEach(folderPath => {
  //         const searchStarterFolderNames = fs.readdirSync(folderPath).filter(name => /starter/.test(name));
  //         if (searchStarterFolderNames.length === 0) {
  //           // skip
  //         } else if (searchStarterFolderNames.length > 1) {
  //           throw new Error("More than one starters.");
  //         } else if (fs.existsSync((starterFolderName = path.resolve(folderPath, searchStarterFolderNames[0], "index.tsx")))) {
  //           // next
  //         } else if (fs.existsSync((starterFolderName = path.resolve(folderPath, searchStarterFolderNames[0], "index.ts")))) {
  //           // next
  //         } else if (fs.existsSync((starterFolderName = path.resolve(folderPath, searchStarterFolderNames[0], "index.jsx")))) {
  //           // next
  //         } else if (fs.existsSync((starterFolderName = path.resolve(folderPath, searchStarterFolderNames[0], "index.js")))) {
  //           // next
  //         } else {
  //           throw new Error(`No index file in folder ${path.resolve(folderPath, searchStarterFolderNames[0])}`);
  //         }
  //       });
  //     if (!starterFolderName) {
  //       throw new Error("No starter in project.");
  //     } else {
  //       config.entry = starterFolderName;
  //     }
  //     return config;
  //   };
  aliacFunc(config);
  //   entryFunc(config);
  return config;
};
